/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Persistencia;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author diego
 */
public class ConexionAdmin {

    private EntityManager em = null;
    private static ConexionAdmin instance = null;

    private ConexionAdmin() {
        try {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("Persistencia");
            em = emf.createEntityManager();
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Explotaron las Conexiones!!!!!!!!");
        }


    }

    public static ConexionAdmin getInstance() {
        if (instance == null) {
            instance = new ConexionAdmin();
        }
        return instance;
    }

    public EntityManager getEntityManager() {
        return em;
    }

    public void begin() {
        em.getTransaction().begin();
    }

    public void commit() {
        em.getTransaction().commit();
    }

    void rollback() {
        em.getTransaction().rollback();
    }
}
